import Vue from 'vue'
import Router from 'vue-router'

import Layout from "@/layout/index.vue";

//导入进度条插件
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

Vue.use(Router)

import VueRouter from "vue-router";

const routes = [
    {
        path: '/login',
        component: () => import('@/views/login/index.vue'),
        hidden: true
    },
    {
        path: '/404',
        component: () => import('@/views/error/404'),
        hidden: true
    },
    {
        path: '/401',
        component: () => import('@/views/error/401'),
        hidden: true
    },
    {
        path: '/',
        component: Layout,
        redirect: 'dashboard',
        children: [
            {
                path: 'dashboard',
                component: () => import('@/views/index'),
                name: "Dashboard",
                meta: { title: '首页', icon: 'dashboard', affix: true }
            },
            {
                path: 'career',
                name: 'Career',
                component: () => import('@/views/career'),
                meta: { title: '岗位' },
            },
            {
                path: 'company',
                name: 'Company',
                component: () => import('@/views/company'),
                meta: { title: '企业' },
            },
            {
                path: 'news',
                name: 'News',
                component: () => import('@/views/news'),
                meta: { title: '校园新闻' }
            },
            {
                path: 'resumes',
                name: 'Resume',
                component: () => import('@/views/resume'),
                meta: { title: '个人简历' }
            },
            {
                path: 'personal',
                name: 'Personal',
                component: () => import('@/views/personal'),
                meta: { title: '个人中心' }
            },
            {
                path: 'details',
                name: 'Details',
                component: () => import('@/views/company/info/index.vue'),
                meta: { title: '公司详情' }
            },
            {
                path: 'info',
                name: 'Info',
                component: () => import('@/views/career/info/index.vue'),
                meta: { title: '职位详情' }
            },
            {
                path: 'news-info',
                name: 'NewsInfo',
                component: () => import('@/views/news/info/index.vue'),
                meta: { title: '新闻详情' }
            }
        ]
    }
]

let routerPush = Router.prototype.push;
let routerReplace = Router.prototype.replace;
// push
Router.prototype.push = function push(location) {
    return routerPush.call(this, location).catch(err => err)
}
// replace
Router.prototype.replace = function push(location) {
    return routerReplace.call(this, location).catch(err => err)
}

const router = new VueRouter({
    mode: "history",
    routes,
})

// 路由进入前
router.beforeEach((to, from , next) => {
    NProgress.start();
    next();
});

//路由进入后
router.afterEach(() => {
    NProgress.done()
})

export default router
